Linux系统参数调优参考

一、系统参数调优

[xxxxx@localhost:/#]vi /etc/sysctl.d/99-sysctl.conf
##added by zhoutao on 2011/10/17 
net.ipv4.tcp_max_syn_backlog = 10240
net.ipv4.tcp_max_tw_buckets = 400000  
net.ipv4.tcp_max_orphans = 60000  
net.ipv4.tcp_synack_retries = 3  
net.ipv4.tcp_fin_timeout = 3  
net.core.rmem_max = 16777216  
net.core.wmem_max = 16777216  
net.core.rmem_default = 1048576  
net.core.wmem_default = 1048576  
net.core.somaxconn = 16384  
net.ipv4.tcp_rmem = 4096 87380 16777216  
net.ipv4.tcp_wmem = 4096 65536 16777216  
net.core.netdev_max_backlog = 3000  
net.ipv4.tcp_congestion_control = cubic  
net.ipv4.ip_local_port_range = 1024 65535  
net.ipv4.tcp_tw_reuse = 1  
net.ipv4.neigh.default.unres_qlen = 6  
net.ipv4.neigh.default.proxy_qlen = 96  
net.ipv4.ip_nonlocal_bind = 1  
net.ipv4.tcp_keepalive_time = 60  
net.ipv4.tcp_keepalive_probes = 3  
net.ipv4.tcp_keepalive_intvl = 10  
fs.file-max = 360000  
net.ipv4.conf.all.log_martians=1  
net.nf_conntrack_max = 25000000  
net.netfilter.nf_conntrack_max = 25000000  
net.netfilter.nf_conntrack_tcp_timeout_established = 180  
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 1  
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60  
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120  

二、文件描述符

[xxx$xxxxxx]: vi /etc/security/limits.conf

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#
#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
*       soft    nofile  65000
*       hard    nofile  65000
# End of file

三、防火墙iptables

传送门

四、MySQL参数调优参考

character-set-server=utf8  
init_connect='SET NAMES utf8'  
slow_query_log=1  
slow_query_log_file=/var/log/mysql/mysql-slow.log  
long_query_time=1  
skip-innodb  
default-storage-engine=MyISAM  
#skip-grant-tables
skip-name-resolve=1  
performance_schema = OFF  
wait_timeout=60  
connect_timeout=10  
interactive_timeout=120  
expire_logs_days = 10  
key_buffer_size = 8M  
max_allowed_packet = 1M  
table_open_cache = 128  
sort_buffer_size = 512K  
net_buffer_length = 8K  
read_buffer_size = 256K  
read_rnd_buffer_size = 512K  
myisam_sort_buffer_size = 4M  
query_cache_size = 0  
query_cache_type = 0  
thread_cache_size = 4  
lower_case_table_names=1  

参数的调优,还需要与mysqltuner配合使用。

五、NGINX参数调优

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
user              www users;  
worker_processes  8;  
worker_rlimit_nofile    100000;  
error_log  /var/log/nginx/error.log;  
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;
pid        /var/run/nginx.pid;  
events {  
    worker_connections  2048;
    use epoll;
}
http {  
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  off;
    error_log /var/log/nginx/error.log crit;
    server_tokens off;
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;
    #keepalive_timeout  0;
    keepalive_timeout  15;
#    limit_conn_zone $binary_remote_addr zone=addr:5m;
#    limit_conn addr 100;
    client_header_buffer_size 16k;
    client_max_body_size 100m;
    large_client_header_buffers 4 32k;
    client_body_temp_path /tmp;

    fastcgi_connect_timeout 300s;
    fastcgi_send_timeout 300s;
    fastcgi_read_timeout 300s;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 8 128k;#8 128
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;
    gzip  on;
    gzip_vary on;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_comp_level 4;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
}

六、php-fpm参数调优

结合平时使用中,发生的错误,观察php-fpm的日志,适当提高或者降低参数值,避免502错误。